<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    form{
        padding: 20px;
        height: auto;
        background-color: skyblue;
        width: 400px;
        margin: 50px auto;
    }
</style>
<body>
<form action="#">
    <div class="form-group">
        <label for="name">UserName</label>
        <input type="text" name="name" class="form-control" id="name" placeholder="UserName">
    </div>
    <div class="form-group">
        <label for="pwd">Password</label>
        <input type="password" name="password" class="form-control" id="pwd" placeholder="Password">
    </div>
    <button type="button" id="bt" class="btn btn-success">登录</button>
</form>

</body>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script>
    $("#bt").click(function () {
        var name = $("#name").val();
        var password = $("#pwd").val();
        $.ajax({
            url:"http://localhost:8080/stusys/LoginServlet",
            type:"POST",
            data:{
                name:name,
                password:password
            },
            dataType:"text",
            success:function (data) {
                if(data != "success"){
                    alert(data);
                }else{
                    location.href="http://localhost:8080/stusys/index.jsp";
                }
            }
        })
    })
</script>
</html>